package com.operator.Activitys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.operator.Activitys.R;
import com.operator.Activitys.adapter.base.BaseRecyclerViewAdapter;
import com.operator.Activitys.bean.SalesRecord;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：金泽云 手机app
 * 类描述：销售记录 适配器
 * 创建人：张飞祥
 * 创建时间：2018/5/29 15:34
 * 修改人：张飞祥
 * 修改时间：2018/5/29 15:34
 * 修改备注：
 */
public class SalesRecordAdapter extends BaseRecyclerViewAdapter {


    //数据集合
    private List<SalesRecord> mList;
    //上下文
    private Context mContext;
    //销售记录 标志（0：号卡销售  1：宽带销售）
    private int mSalesTag = 0;

    //数据装填方法
    public SalesRecordAdapter(Context mContext,int mSalesTag,List<SalesRecord> mList) {
        super(mContext, mList);
        this.mList = mList;
        this.mContext = mContext;
        this.mSalesTag = mSalesTag;
    }


    @Override
    protected int getLayoutItemResId() {
        return R.layout.item_sales;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        if (viewHolder instanceof SalesRecordViewHolder) {


            //TODO 获取销售记录 viewHolder
            final SalesRecordViewHolder holder = (SalesRecordViewHolder) viewHolder;
            //TODO  将数据保存在itemView的Tag中，以便点击时进行获取
            holder.itemView.setTag(position);
            //TODO  获取数据源 第 i 个 实体数据
            SalesRecord sales = mList.get(position);

            /**
             * 设置 数据源
             */
            //TODO 动态判断 销售记录 Tag,做相应的 处理
            if (mSalesTag == 0){
                //隐藏姓名
                holder.tvItemSalesName.setVisibility(View.GONE);
                //设置电话号码
                holder.tvItemSalesId.setText(sales.getTelNumber());
                //设置资费
                holder.tvItemSalesPrice.setText(sales.getTelephoneSetTitle());
            }else{
                //设置宽带号码
                holder.tvItemSalesId.setText(sales.getAccount());
                //显示姓名
                holder.tvItemSalesName.setVisibility(View.VISIBLE);
                //设置姓名
                holder.tvItemSalesName.setText(sales.getCustomerName());
                //设置资费
                holder.tvItemSalesPrice.setText(sales.getPrice());
            }

            //设置销售日期
            holder.tvItemSalesDate.setText(sales.getCreateTime());
            //设置已返金额
            holder.tvItemSalesReturn.setText(sales.getCashback()+"");
        }
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new SalesRecordViewHolder(view);
    }

    /**
     * ViewHolder
     */
    public class SalesRecordViewHolder extends RecyclerView.ViewHolder {

        //号码
        @Bind(R.id.tv_item_sales_id)
        TextView tvItemSalesId;
        //资费
        @Bind(R.id.tv_item_sales_price)
        TextView tvItemSalesPrice;
        //销售日期
        @Bind(R.id.tv_item_sales_date)
        TextView tvItemSalesDate;
        //姓名
        @Bind(R.id.tv_item_sales_name)
        TextView tvItemSalesName;
        //已返
        @Bind(R.id.tv_item_sales_return)
        TextView tvItemSalesReturn;

        public SalesRecordViewHolder(View itemView) {
            super(itemView);
            //绑定控件
            ButterKnife.bind(this, itemView);
            //屏幕适配
            AutoUtils.autoSize(itemView);
        }
    }
}
